class CashApplyController{
    constructor($state,$rootScope,$scope,UserService,AccountService){
        Object.assign(this,{$state,$rootScope,$scope,UserService,AccountService});
        this.$rootScope.currentGroup= this.$state.params.cg;
        this.init();
        this.cash_amount = "";
        this.cash_pwd = "";
    }

    init (){
        let self = this;
        this.AccountService.getAccountInfo().then(_success).catch(_error);
        function _success(data) {
            self.$rootScope.lotteryAccountInfo =data;
        };
        function _error(reason) {
            layer.msg(reason.text, {time: 3000});
        };
    }

    applyCash(){
        let self = this;
        let param = {};
        param.cash_amount = self.cash_amount;
        param.cash_pwd = self.cash_pwd;
        self.AccountService.cashApply(param).then(_success).catch(_error);
        function _success(data) {
            if(data.success==true){
                layer.open({
                   icon:1,
                   title:"信息",
                   content:"成功发出提现申请",
                   btn:["知道了"],
                   yes:function (index,layerno) {
                       layer.close(index);
                       self.$state.go("dashboard.accountdash.cashlist");
                   }
               });
            }
        }
        function _error(reason) {
            let type = typeof reason;
            let c1 = type=='object'?reason.text:reason;
            layer.open({
               icon:2,
               title:"错误！",
               content:c1,
               btn:["知道了"],
               yes:function (index,layerno) {
                   if(c1.indexOf("账户未绑定账户信息")!=-1){
                       self.$state.go("dashboard.accountdash.bindaccountcash");
                   }
                   layer.close(index);
               }
           });
        };
    }
}
CashApplyController.$inject = ["$state","$rootScope","$scope","UserService","AccountService"];

export default CashApplyController;